<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{% block title %}{% endblock %} - {{ site_config.get_config('site_name', 'PPress') }}管理后台</title>
    <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
    <script src="{{ url_for('static', filename='default/vendor/3.4.5') }}"></script>
    <script src="{{ url_for('static', filename='default/vendor/alpinejs3.14.3.js') }}"></script>
    <style>
        [x-cloak] { display: none !important; }
        .transform { transform-origin: center; }
        .rotate-180 { transform: rotate(180deg); }
        html, body {
            height: 100%;
        }
        body {
             display: flex;
             flex-direction: column;
             min-height: 100vh;
         }
        main {
            flex: 1 0 auto;
            width: 100%;
        }
        /* Logo 样式 */
        .logo-circle {
            position: relative;
            overflow: hidden;
            transform: translateZ(0);  /* 启用硬件加速 */
            background: linear-gradient(135deg, #0180FF, #0178FF);  /* 亮色模式下的渐变 */
        }

        .logo-circle::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 60%);
            z-index: 1;
            border-radius: 9999px;
        }

        .dark .logo-circle {
            background: linear-gradient(135deg, #0180FF, #0178FF);  /* 暗色模式下的渐变 */
        }

        /* Logo 悬停效果 */
        .logo-circle:hover {
            transform: scale(1.05);
            box-shadow: 0 0 20px rgba(1, 128, 255, 0.6);
        }
    </style>
</head>
<body class="bg-gray-100">
<!-- 顶部导航栏 -->
<nav class="bg-white shadow-sm" x-data="{ mobileMenuOpen: false }">
    <div class="max-w-7xl mx-auto px-4">
        <div class="flex justify-between h-16 relative">
            <div class="flex items-center" onclick='window.location.href="{{ url_for('admin.dashboard') }}"'>
                <h1 class="text-xl font-medium text-gray-900 flex items-center">
                    <div class="logo-circle w-8 h-8 rounded-full flex items-center justify-center text-white font-bold text-xl transition-all duration-300">
                        P
                    </div>
                    <span style="margin-left: 10px">
                        PPress 后台管理
                    </span>
                </h1>
            </div>

            <!-- 移动端菜单按钮 -->
            <div class="sm:hidden flex items-center">
                <button @click="mobileMenuOpen = !mobileMenuOpen"
                        type="button"
                        class="text-gray-500 hover:text-gray-600 p-2">
                    <svg class="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
                    </svg>
                </button>
            </div>

            <div class="hidden sm:flex items-center space-x-4">
                {% set nav_groups = [
                {
                'title': '内容管理',
                'icon': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9.5a2 2 0 00-2-2h-2m-4 0h4"></path>',
                'menu_items': [
                ('admin.articles', '文章管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9.5a2 2 0 00-2-2h-2m-4 0h4"></path>'),
                ('admin.comments', '评论管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path>'),
                ('admin.categories', '分类管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path>'),
                ('admin.custom_pages', '页面管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>'),
                ('admin.tags', '标签管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path>'),
                ('admin.manage_files', '附件管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"></path>')

                ]
                },
                {
                'title': '用户管理',
                'icon': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path>',
                'menu_items': [
                ('admin.users', '用户列表', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path>'),
                ('admin.histories', '浏览历史', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>')
                ]
                },
                {
                'title': '系统管理',
                'icon': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"></path>',
                'menu_items': [
                ('admin.site_config', '网站配置', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>'),
                ('admin.themes', '主题管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01"></path>'),
                ('admin.plugins', '插件管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"></path>'),
                ('admin.routes', '路由管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path>'),
                ('admin.cache_stats', '缓存管理', '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"></path>')
                ]
                }
                ] %}

                <!-- 仪表盘单独显示 -->
                <a href="{{ url_for('admin.dashboard') }}"
                   class="px-3 py-2 text-gray-700 hover:text-blue-600 border-b-2 flex items-center {% if request.endpoint == 'admin.dashboard' %}border-blue-600 text-blue-600{% else %}border-transparent{% endif %}">
                    <svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
                    </svg>
                    仪表盘
                </a>

                {% for group in nav_groups %}
                <div class="relative" x-data="{ open: false }" @click.away="open = false">
                    <button @click="open = !open"
                            class="px-3 py-2 text-gray-700 hover:text-blue-600 border-b-2 flex items-center {% if is_active_group(group.menu_items) or is_current_menu(group.menu_items) %}border-blue-600 text-blue-600{% else %}border-transparent{% endif %}">
                        <svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            {{ group.icon|safe }}
                        </svg>
                        {{ group.title }}
                        <svg class="w-4 h-4 ml-1" :class="{'transform rotate-180': open}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>

                    <div x-show="open"
                         x-transition:enter="transition ease-out duration-100"
                         x-transition:enter-start="transform opacity-0 scale-95"
                         x-transition:enter-end="transform opacity-100 scale-100"
                         x-transition:leave="transition ease-in duration-75"
                         x-transition:leave-start="transform opacity-100 scale-100"
                         x-transition:leave-end="transform opacity-0 scale-95"
                         class="absolute left-0 mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50">
                        <div class="py-1">
                            {% for endpoint, title, icon in group.menu_items %}
                            <a href="{{ url_for(endpoint) }}"
                               class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 {% if request.endpoint == endpoint %}bg-gray-100 text-blue-600{% endif %}">
                                <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    {{ icon|safe }}
                                </svg>
                                {{ title }}
                            </a>
                            {% endfor %}
                        </div>
                    </div>
                </div>
                {% endfor %}

                <div class="border-l border-gray-200 h-6 mx-2"></div>
                <!-- 退出登录按钮 -->
                <a href="javascript:void(0)" onclick="confirmLogout()"
                   class="px-3 py-2 text-gray-700 hover:text-red-600 border-b-2 border-transparent hover:border-red-600 flex items-center transition-colors duration-200">
                    <svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1">
                        </path>
                    </svg>
                    退出登录
                </a>


                <a href="{{ url_for('blog.index') }}"
                   class="px-3 py-2 text-gray-700 hover:text-blue-600 border-b-2 border-transparent flex items-center">
                    <svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
                    </svg>
                    返回首页
                </a>

            </div>
        </div>

        <!-- 移动端菜单面板 -->
        <div x-show="mobileMenuOpen"
             x-cloak
             @click.away="mobileMenuOpen = false"
             class="absolute inset-x-0 top-16 bg-white shadow-lg border-t z-50 sm:hidden">
            <div class="py-2">
                <!-- 仪表盘 -->
                <a href="{{ url_for('admin.dashboard') }}"
                   class="block px-4 py-2 text-gray-700 hover:bg-gray-100 {% if request.endpoint == 'admin.dashboard' %}bg-gray-100 text-blue-600{% endif %}">
                    <div class="flex items-center">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
                        </svg>
                        仪表盘
                    </div>
                </a>

                <!-- 遍历菜单组 -->
                {% for group in nav_groups %}
                <div x-data="{ open: {% if is_active_group(group.menu_items) or is_current_menu(group.menu_items) %}true{% else %}false{% endif %} }">
                    <button @click="open = !open"
                            class="w-full px-4 py-2 text-left hover:bg-gray-100 flex items-center justify-between {% if is_active_group(group.menu_items) or is_current_menu(group.menu_items) %}bg-gray-100 text-blue-600{% else %}text-gray-700{% endif %}">
                        <div class="flex items-center">
                            <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                {{ group.icon|safe }}
                            </svg>
                            {{ group.title }}
                        </div>
                        <svg class="w-4 h-4 transform transition-transform duration-200"
                             :class="{'rotate-180': open}"
                             fill="none"
                             stroke="currentColor"
                             viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div x-show="open"
                         x-transition:enter="transition ease-out duration-100"
                         x-transition:enter-start="transform opacity-0 scale-95"
                         x-transition:enter-end="transform opacity-100 scale-100"
                         class="bg-gray-50">
                        {% for endpoint, title, icon in group.menu_items %}
                        <a href="{{ url_for(endpoint) }}"
                           class="block pl-12 pr-4 py-2 hover:bg-gray-100 {% if request.endpoint == endpoint %}bg-gray-100 text-blue-600{% else %}text-gray-700{% endif %}">
                            {{ title }}
                        </a>
                        {% endfor %}
                    </div>
                </div>
                {% endfor %}

                <a href="javascript:void(0)" onclick="confirmLogout()"
                   class="block px-4 py-2 text-gray-700 hover:text-red-600">
                    <div class="flex items-center">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1">
                            </path>
                        </svg>
                        退出登录
                    </div>
                </a>

                <!-- 返回首页 -->
                <a href="{{ url_for('blog.index') }}"
                   class="block px-4 py-2 text-gray-700 hover:bg-gray-100">
                    <div class="flex items-center">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
                        </svg>
                        返回首页
                    </div>
                </a>
            </div>
        </div>
    </div>
</nav>

<!-- 主内容区 -->
<main class="flex-1 max-w-7xl mx-auto py-6 px-4">
    {% block content %}{% endblock %}
</main>

<!-- 页脚版权信息 -->
<footer class="bg-white dark:bg-gray-800 border-t dark:border-gray-700 w-full mt-auto">
    <div class="max-w-7xl mx-auto py-4 px-6">
        {{ get_encrypted_copyright()|safe }}
    </div>
</footer>

{% include 'components/alert.html' %}
<!-- 添加确认退出的脚本 -->
<script>
    function confirmLogout() {
        showAlert('确定要退出登录吗？', 'warning', '提示', function() {
            window.location.href = "{{ url_for('auth.logout') }}";
        });
    }
</script>
</body>
</html> 